<template>
  <div id="app">
    <div class="header">
      <img class="bg-img" :src="bgImg" alt>
      <div class="login-form">
        <p class="title">登录</p>
        <div class="content">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
            <el-form-item prop="account">
              <el-input
                prefix-icon="icon-web-user"
                v-model="ruleForm.account"
                placeholder="请输入已验证的手机号或邮箱"
              ></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input
                type="password"
                prefix-icon="icon-web-lock"
                v-model="ruleForm.password"
                placeholder="请输入登录密码"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')">立即登录</el-button>
              <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
            </el-form-item>
          </el-form>
          <div>
            还没有账号
            <a href="./login.html">前去注册</a>
          </div>
        </div>
      </div>
    </div>
    <div class="footer">
      <p>Copyright © 2017 新开普电子股份有限公司 (Newcapec Electronics Co.,Ltd.)</p>
      <p>豫ICP备08102576号-5</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      bgImg: require('@/assets/img/ground.png'),
      ruleForm: {
        account: '',
        password: ''
      },
      rules: {
        account: [
          { required: true, message: '请输入已验证的手机号或邮箱', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入登录密码', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.signin();
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    async signin() {
      let res = await this.$http.signin(this.ruleForm);
      this.$message({
        message: res.message,
        type: 'success'
      })
      // window.sessionStorage.setItem('user', JSON.stringify(res.data))
      // window.location.replace('./index.html')
      window.sessionStorage.setItem('token', res.token);
      window.location.replace('./index.html');
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style lang="less" >
* {
  margin: 0;
  box-sizing: border-box;
}
html,
body,
#app {
  width: 100%;
  height: 100%;
}
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  .header {
    width: 100%;
    height: 85%;
    // background-image: url(../../assets/img/ground.png);
    // background-size: 100% 100%;
    position: relative;
    .bg-img {
      width: 100%;
      height: 100%;
    }
  }
  .footer {
    width: 100%;
    height: 15%;
    font-size: 13px;
    color: #4d4d4d;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    p {
      margin-bottom: 10px;
    }
  }
  .login-form {
    width: 360px;
    // height: 420px;
    background-color: #ffffff;
    border-radius: 8px;
    position: absolute;
    top: 150px;
    left: 50%;
    transform: translateX(-50%);
    .title {
      font-size: 24px;
      color: #fe6601;
      text-align: center;
      padding-top: 30px;
    }
    .content {
      padding: 30px;
      .el-button {
        width: 100%;
        height: 35px;
        background-color: #fe6601;
        border: none;
      }
    }
  }
}
</style>
